package xyz.thoughtset.viewer.common.log.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import xyz.thoughtset.viewer.common.log.constant.LogInfoExConstant;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

@Configuration
public class LogInfoExConfig {

    @Bean(name = LogInfoExConstant.EX_NAME)
    @ConditionalOnMissingBean(name = LogInfoExConstant.EX_NAME)
    public Executor saveExcExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(1);
        executor.setMaxPoolSize(6);
        executor.setQueueCapacity(128);
        executor.setKeepAliveSeconds(16);
        executor.setThreadNamePrefix(LogInfoExConstant.EX_NAME+"-"); // 线程名称前缀
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        executor.initialize();
        return executor;
    }

//    @Bean
//    @ConditionalOnMissingBean(name = LogInfoExConstant.EX_CHECK)
//    public Executor countFilePageExecutor() {
//        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
//        executor.setCorePoolSize(1);
//        executor.setMaxPoolSize(16);
//        executor.setQueueCapacity(128);
//        executor.setKeepAliveSeconds(60);
//        executor.setThreadNamePrefix(LogInfoExConstant.EX_CHECK+"-"); // 线程名称前缀
//        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
//        executor.initialize();
//        return executor;
//    }

}
